package cn.wolfcode.crm;

import cn.wolfcode.crm.web.interceptor.LoginInterceptor;
import cn.wolfcode.crm.web.interceptor.PermissionInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@MapperScan("cn.wolfcode.crm.mapper")
public class SpringbootCrmApplication implements WebMvcConfigurer{

    @Bean
    public LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }
    @Bean
    public PermissionInterceptor permissionInterceptor(){
        return new PermissionInterceptor();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

      registry.addInterceptor(loginInterceptor())
        //需要拦截的路径
        .addPathPatterns("/**")
        //放过的路径
        .excludePathPatterns("/css/**")
        .excludePathPatterns("/js/**")
        .excludePathPatterns("/images/**")
        .excludePathPatterns("/xlstemplates/**")
        .excludePathPatterns("/loginUser/**");

        registry.addInterceptor(permissionInterceptor())
        //需要拦截的路径
        .addPathPatterns("/**")
        //放过的路径
        .excludePathPatterns("/css/**")
        .excludePathPatterns("/js/**")
        .excludePathPatterns("/images/**")
        .excludePathPatterns("/xlstemplates/**")
        .excludePathPatterns("/loginUser/**");
    }



    public static void main(String[] args){

        SpringApplication.run(SpringbootCrmApplication.class, args);

    }
}
